import request from '@/utils/request';
import { partialRight } from 'lodash';

export async function getStandProductByPage(params: any) {
  return request('/api/design/getStandProductByPage', {
    method: 'POST',
    data: params,
  });
}
export async function getStandProductByStandTypeName(para: any) {
  return request('/api/design/getStandProductByStandTypeName', {
    method: 'POST',
    params: {
      standTypeName: para,
    },
  });
}

export async function addStandProduct(para: any) {
  return request('/api/design/addStandProduct', {
    method: 'POST',
    requestType: 'form',
    headers: { 'Content-Type': 'multipart/form-data' }, //上传文件一般使用multipart/form-data
    params: {
      bopCode: para.bopCode,
      standTypeDesc: para.standTypeDesc,
      memo: para.memo,
      standDesignWorkHour: para.standDesignWorkHour,
      standManufactWorkHour: para.standManufactWorkHour,
      standTypeName: para.standTypeName,
      materialCode: para.materialCode,
      materialInfoId: para.materialInfoId,
      materialName: para.materialName,
    },
  });
}

export async function updateStandProduct(para: any) {
  return request('/api/design/updateStandProduct', {
    method: 'POST',
    requestType: 'form',
    params: {
      bopCode: para.bopCode,
      standTypeCode: para.standTypeCode,
      standTypeDesc: para.standTypeDesc,
      memo: para.memo,
      standDesignWorkHour: para.standDesignWorkHour,
      standManufactWorkHour: para.standManufactWorkHour,
      standTypeName: para.standTypeName,
      standTypeId: para.standTypeId,
      materialCode: para.materialCode,
      materialInfoId: para.materialInfoId,
      materialName: para.materialName,
    },
  });
}

export async function delStandProduct(params: any) {
  return request('/api/design/delStandProduct', {
    method: 'POST',
    data: params,
  });
}

export async function exportStandProduct(params: any) {
  return request('/api/design/exportStandProduct', {
    method: 'POST',
    data: params,
    responseType: 'blob',
  });
}

export async function getProductTypeList(params: any) {
  return request('/api/design/getProductTypeList', {
    method: 'POST',
  });
}

export async function getBopCodeAndName(params: any) {
  return request('/api/design/getBopCodeAndName', {
    method: 'POST',
  });
}

// 图纸上传
export async function uploadStandFileInfoDrawing(para: any) {
  return request('/api/design/uploadStandFileInfoDrawing', {
    method: 'POST',
    requestType: 'form',
    headers: {
      'Content-Type': 'multipart/form-data; boundary=----WebKitFormBoundaryX72QZDdfwlF5U73J',
    },
    data: para.file,
    params: {
      standTypeCode: para.standTypeCode,
      standTypeDesc: para.standTypeDesc,
      category: para.category,
      memo: para.memo,
      standTypeId: para.standTypeId,
      standTypeName: para.standTypeName,
    },
  });
}

// BOM上传
export async function uploadStandFileInfoBom(para: any) {
  return request('/api/design/uploadStandFileInfoBom', {
    method: 'POST',
    requestType: 'form',
    data: para.file,
    params: {
      standTypeCode: para.standTypeCode,
      standTypeDesc: para.standTypeDesc,
      category: para.category,
      memo: para.memo,
      standTypeId: para.standTypeId,
      standTypeName: para.standTypeName,
    },
  });
}

export async function getStandFileType(params: any) {
  return request('/api/design/getStandFileType', {
    method: 'POST',
  });
}

export async function downloadFile(para: any) {
  return request('/api/design/downloadFile', {
    method: 'GET',
    responseType: 'blob',
    headers: { 'Content-Type': 'application/json' },
    getResponse: true,
    params: {
      fileCode: para.fileCode,
    },
  });
}

export async function getFileByFileCode(para: any) {
  return request('/api/design/getFileByFileCode', {
    method: 'POST',
    params: {
      fileCode: para.fileCode,
    },
  });
}

export async function getDrawingTypeList(params: any) {
  return request('/api/design/getDrawingTypeList', {
    method: 'POST',
  });
}

// BOM模板下载
export async function bom_downloadFile(para: any) {
  return request('/api/project/downloadFile', {
    method: 'GET',
    responseType: 'blob',
    data: para,
    params: {
      id: para.id,
    },
  });
}

// 工时模板导出
export async function exportStandProductProcessInfoByStandTypeIds(para: any) {
  return request('/api/design/exportStandProductProcessInfoByStandTypeIds', {
    method: 'POST',
    data: para,
    responseType: 'blob',
  });
}

// 工时上传
export async function uploadStandProductProcessInfo(para: any) {
  return request('/api/design/uploadStandProductProcessInfo', {
    method: 'POST',
    requestType: 'form',
    headers: {
      'Content-Type': 'multipart/form-data; boundary=----WebKitFormBoundaryX72QZDdfwlF5U73J',
    },
    data: para.file,
  });
}

/**
 * @description:标准柜体审核，未提交->待审批
 * @param {any} para
 * @return {*}
 */
export async function submitStandProduct(para: any) {
  return request('/api/design/submitStandProduct', {
    method: 'POST',
    params: {
      standTypeId: para.id,
    },
  });
}
/**
 * @description:标准柜体审核，未提交->待审批
 * @param {any} para
 * @return {*}
 */
export async function approveStandProduct(para: any) {
  return request('/api/design/approveStandProduct', {
    method: 'POST',
    params: {
      standTypeId: para.standTypeId,
      state: para.state,
      approveText: para.approveText,
    },
  });
}
export default {
  getStandProductByPage,
  addStandProduct,
  updateStandProduct,
  delStandProduct,
  exportStandProduct,
  getProductTypeList,
  getStandProductByStandTypeName,
  submitStandProduct,
  approveStandProduct,
};
